import Vue from "vue"
import VueRouter from "vue-router"

// 解决vue 路由多次点击报错
const originalPush = VueRouter.prototype.push
VueRouter.prototype.push = function push(location) {
    return originalPush.call(this, location).catch(err => err)
}
const Home = () => import('../views/Home/Home.vue')
const Categroy = () => import('../views/Categroy/Categroy')
const Cart = () => import('../views/Cart/Cart')
const User = () => import('../views/User/User')
// 1.安装插件
Vue.use(VueRouter)
// 2.创建router
const routes = [
    {
        path: "/",
        // 重定向redirect  默认
        redirect: "/home"

    },
    {
        path: '/home',
        component: Home,
        meta: {
            title: '首页'
        },
    },
    {
        path: '/about',
        name: 'About',
        component: Categroy,
        meta: {
            title: '关于'
        },
    },
    {
        path: '/cart',
        name: 'Cart',
        component: Cart,
        meta: {
            title: '购物车'
        },
    },
    {
        path: '/user',
        name: 'User',
        component: User,
        meta: {
            title: '关于'
        },
    },

]
const router = new VueRouter({
    mode: 'history',
    routes
})
export default router